﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CoastalClimbing.Code;
using System.Data;
using System.Collections;

namespace CoastalClimbing
{
    public partial class Walls : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.BindInfo();
            }
        }

        private void BindInfo()
        {
            try
            {
                bool visible = false;
                var cf = ClimbingFloor.Downstairs;

                if(Request.QueryString["f"] != null)
                {
                    string qs = Request.QueryString["f"].ToString();
                    
                    if(qs.Equals("u"))
                    {
                        visible = true;
                        cf = ClimbingFloor.Upstairs;
                    }
                }
                pnlUpstairs.Visible = visible;
                pnlDownstairs.Visible = !visible;
                litClimbingWall.Text = cf.ToString();

                DataTable chartInfo = DAL.GetChartData(cf);

                List<DictionaryEntry> data = new List<DictionaryEntry>();
                List<DictionaryEntry> big = new List<DictionaryEntry>();

                foreach (DataRow row in chartInfo.Rows)
                {
                    string rating = row["RATING"].ToString();

                    //if(rating.Replace("V", "").Count() == 1)
                    //{
                    //    data.Add(new DictionaryEntry(rating, row["NUMOF"].ToString()));
                    //}
                    //else
                    //{
                        big.Add(new DictionaryEntry(rating, row["NUMOF"].ToString()));
                    //}
                }

                data.AddRange(big);

                if(data != null && data.Count > 0)
                {
                    chtRoutes.Visible = true;
                    chtRoutes.ImageStorageMode = System.Web.UI.DataVisualization.Charting.ImageStorageMode.UseImageLocation;                
                    chtRoutes.Series["Routes"].Points.DataBindXY(data, "KEY", data, "VALUE");
                    chtRoutes.ChartAreas[0].AxisX.Interval = 1;   
                }
                else
                {
                    chtRoutes.Visible = false;
                }             
            }
            catch { }
        }
    }

    public enum ClimbingFloor
    {
        Downstairs = 0,
        Upstairs = 1
    }    
}